package com.godyao.mall.sms.controller;

import com.godyao.mall.core.model.ResultMsg;
import com.godyao.mall.core.utils.PageUtils;
import com.godyao.mall.sms.entity.HomeAdvEntity;
import com.godyao.mall.sms.service.HomeAdvService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 首页轮播广告
 *
 * @author godyao
 * @email godyao0801@qq.com
 * @date 2022-04-19 15:22:30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("sms/homeadv")
public class HomeAdvController {

    private final HomeAdvService homeAdvService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public ResultMsg list(@RequestParam Map<String, Object> params){
        PageUtils page = homeAdvService.queryPage(params);

        return ResultMsg.resultSuccess(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public ResultMsg info(@PathVariable("id") Long id){
		HomeAdvEntity homeAdv = homeAdvService.getById(id);

        return ResultMsg.resultSuccess(homeAdv);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public ResultMsg save(@RequestBody HomeAdvEntity homeAdv){
		homeAdvService.save(homeAdv);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public ResultMsg update(@RequestBody HomeAdvEntity homeAdv){
		homeAdvService.updateById(homeAdv);

        return ResultMsg.resultSuccess("OK");
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public ResultMsg delete(@RequestBody Long[] ids){
		homeAdvService.removeByIds(Arrays.asList(ids));

        return ResultMsg.resultSuccess("OK");
    }

}
